//显示增量启用状态
function showStrategyIncrementEnable(driver) {
	var $incrementEnable = $('#driverStrategyIncrementEnable');
	var $incrementEnableCheck = $incrementEnable.find("input[type='checkbox']");
	// 设置增量开关默认值为false
	$incrementEnableCheck.val("false");
	// 回现增量配置
	if (driver.policy.increment) {
		// 获取驱动增量启用状态值
		var enable = driver.policy.increment.enable == "true";
		$incrementEnableCheck.prop({
			checked : enable
		});
		// 获取当前值
		$incrementEnableCheck.val(enable);
	}
	// 初始化switch插件
	$incrementEnable.find("input").bootstrapSwitch({
		onText : '启用',
		offText : '禁用'
	}).on('switchChange.bootstrapSwitch', function(event, state) {
		// 获取当前值
		$incrementEnableCheck.val(state);
	});
}

// 显示增量策略
function showStrategyIncrementMysql(driver) {
	var config = driver.sourceMapping.config;
	if(config.driverClassName=='com.mysql.jdbc.Driver'){
		$("#sourceStrategyIncrementDatabaseMysql").removeClass("hidden");
		// 回现驱动数据源的信息
		var url = config.url;
		var urlInfo = url.split(/[:/?]/);
		$("#sourceStrategyIncrementDatabase").val(urlInfo[6]);
		$("#sourceStrategyIncrementTable").val(config.table);
		if(driver.policy.increment){
			$("#sourceStrategyIncrementIp").val(driver.policy.increment.ip);
			$("#sourceStrategyIncrementPort").val(driver.policy.increment.port);
			$("#sourceStrategyIncrementInstance").val(driver.policy.increment.instance);
		}
	}
}

//显示增量策略Oracle
function showStrategyIncrementOracle(driver) {
	var config = driver.sourceMapping.config;
	if(config.driverClassName=='oracle.jdbc.OracleDriver'){
		$("#sourceStrategyIncrementDatabaseOracle").removeClass("hidden");
		
		// 回现驱动数据源的信息
		var $scanAll = $('#sourceStrategyIncrementScanAll');
		// 初始化icheck插件
		$scanAll.find("input").iCheck({
			labelHover : false,
			cursor : true,
			radioClass : 'iradio_flat-blue',
		});

		var increment = driver.policy.increment;
		var scanAll = 'true'==increment.scanAll+'' ? 1 : 0;
		// 默认渲染运行日志
		$scanAll.find("input").eq(scanAll).iCheck("check");
		// 字典
		$("#sourceStrategyIncrementDictionaryPath").val(increment.dictionary);
	}
}

//显示增量策略ldap
function showStrategyIncrementLdap(driver) {
	$("#sourceStrategyIncrementLdap").removeClass("hidden");
	var config = driver.sourceMapping.config;
	$("#ldapStrategyIncrementUrl").val(config.url);
	$("#ldapStrategyIncrementBase").val(config.base);
	$("#ldapStrategyIncrementUserDn").val(config.userDn);
	// 回显读取范围
	if (driver.policy.increment) {
		var searchScope = driver.policy.increment.searchScope;
		$("#ldapStrategyIncrementSearchScope option[value='"+searchScope+"']").attr("selected","selected");
	}
}

//显示增量策略Webservice
function showStrategyIncrementWebservice(driver) {
	// 隐藏标题
	$("#sourceStrategyIncrementTitle").addClass("hidden");
}

$(function() {
	// 初始化增量启用状态开关
	showStrategyIncrementEnable(driver);

	var connectorType = driver.sourceMapping.connector;	
	switch (connectorType) {
	case ConnectorConstantDatabase:
		// 显示增量策略Mysql
		showStrategyIncrementMysql(driver);
		// 显示增量策略Oracle
		showStrategyIncrementOracle(driver);
		break;
	case ConnectorConstantLdap:
		// 显示增量策略ldap
		showStrategyIncrementLdap(driver);
		break;
	case ConnectorConstantWebService:
		// 显示增量策略webservice
		showStrategyIncrementWebservice(driver);
		break;
	default:
		break;
	}
});